//
//  StandardBeatView.m
//  gong
//
//  Created by echo on 14-3-6.
//  Copyright (c) 2014年 echo. All rights reserved.
//

#import "StandardBeatView.h"

@implementation StandardBeatView
{
    DanceMusic *_danceMusic;
    int _adjustCoff;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    if (_danceMusic) {
        CGContextRef context = UIGraphicsGetCurrentContext();
        
        if (context) {
            CGContextBeginPath(context);
            CGContextSetRGBStrokeColor (context, 255.0/ 255.0, 0.0/ 255.0, 0.0/ 255.0, 1.0);
            CGContextSetLineWidth(context, 2.0 );
            
            for (int i=0; i<_danceMusic.strongBeatPositionArray.count; i++) {
                NSTimeInterval position = [_danceMusic.strongBeatPositionArray[i] doubleValue] * _adjustCoff;
                CGContextMoveToPoint(context, position, 0);
                CGContextAddLineToPoint(context, position, self.frame.size.height);
                CGContextStrokePath(context);
            }

//            CGContextSetRGBStrokeColor (context, 0.0/ 255.0, 0.0/ 255.0, 255.0/ 255.0, 1.0);
//            
//            for (int i=0; i<_danceMusic.weakBeatPositonArray.count; i++) {
//                NSTimeInterval position = [_danceMusic.weakBeatPositonArray[i] doubleValue] * _adjustCoff;
//                CGContextMoveToPoint(context, position, 0);
//                CGContextAddLineToPoint(context, position, self.frame.size.height);
//                CGContextStrokePath(context);
//            }

        }

    }
}

- (void)drawStandardBeat:(DanceMusic*)danceMusic
{
    _adjustCoff = 100;
    self.frame = CGRectMake(self.superview.frame.size.width/2, self.frame.origin.y, danceMusic.duration * _adjustCoff, self.frame.size.height);
    NSLog(@"canvas frame is %@", NSStringFromCGRect(self.frame));
    _danceMusic = danceMusic;
}

@end
